'''
radius = 2.5
centers = [(2.5*3/2, 2.5*math.sqrt(3)/2),(-2.5*3/2, -2.5*math.sqrt(3)/2),(2.5*3/2, -2.5*math.sqrt(3)/2),(-2.5*3/2, 2.5*math.sqrt(3)/2),(0,0),(0,2.5*math.sqrt(3)),(0,-2.5*math.sqrt(3))]

# 创建图像和坐标轴
fig, ax = plt.subplots()

# 绘制每个圆
for center in centers:
    circle = plt.Circle(center, radius, fill = False, edgecolor = 'blue')
    ax.add_artist(circle)
'''
import matplotlib.pyplot as plt
import numpy as np
# import math
from math import *

# def calculate_centers(radius, layers):
#     centers = []
#     # 添加中心圆
#     centers.append((0, 0))
#
#     # 计算每层的圆心
#     for layer in range(1, layers + 1):
#         # 每层的圆的数量
#         num_circles = 6 * layer
#         for i in range(num_circles):
#             angle = 2 * math.pi * i / num_circles
#             x = layer * radius * math.sqrt(3) * math.sin(angle)
#             y = layer * radius * math.sqrt(3) * math.cos(angle)
#             centers.append((x, y))
#             print(x, y)
#     return centers
#
# # 定义圆的参数
# radius = 5
# layers = 2  # 中心的圆形被包围的层数
#
# # 计算中心点坐标
# centers = calculate_centers(radius, layers)

# 使用上面的计算 精度不准，直接使用递归，把每个圆当成中心圆，周围都画6个圆
# 重复画的颜色更深一点，如何避免？？？
def draw_honeycomb(ax, center, radius, depth, max_depth, drawn_centers):
    if depth > max_depth:
        return

    # 定义蜂窝结构的六个邻居圆心的相对位置
    neighbors = [
        (center[0], center[1] + radius * np.sqrt(3)),
        (center[0], center[1] - radius * np.sqrt(3)),
        (center[0] + radius * 1.5, center[1] + radius * np.sqrt(3) / 2),
        (center[0] + radius * 1.5, center[1] - radius * np.sqrt(3) / 2),
        (center[0] - radius * 1.5, center[1] + radius * np.sqrt(3) / 2),
        (center[0] - radius * 1.5, center[1] - radius * np.sqrt(3) / 2)
    ]

    for neighbor in neighbors:
        if neighbor not in drawn_centers:
            print(neighbor)
            circle = plt.Circle(neighbor, radius, fill=False, edgecolor='blue')
            ax.add_artist(circle)
            drawn_centers.add(neighbor)
        draw_honeycomb(ax, neighbor, radius, depth + 1, max_depth, drawn_centers)

# radius = 8.75  # Ice Crystaleyezer Kit 8.75 tiles (35 wall units)
radius = 2.5  # Scaled Furnace 2 tiles (8 wall units) dontstarve.wiki.gg显示为2格地皮，但是mod显示是2.5格？
# centers = [(0, 0), (0, sqrt(3)), (0, -sqrt(3)), (0, sqrt(3) * 2), (0, -sqrt(3) * 2),
#            (3 / 2, sqrt(3) / 2), (-3 / 2, sqrt(3) / 2), (3 / 2, -sqrt(3) / 2), (-3 / 2, -sqrt(3) / 2),
#            (3 / 2, sqrt(3) / 2 * 3), (-3 / 2, sqrt(3) / 2 * 3), (3 / 2, -sqrt(3) / 2 * 3), (-3 / 2, -sqrt(3) / 2 * 3),
#            (3, sqrt(3)), (-3, sqrt(3)), (3, -sqrt(3)), (-3, -sqrt(3)), (3, 0), (-3, 0)]
#
# scaled_centers = [(x * radius, y * radius) for x, y in centers]
#
# 创建图像和坐标轴
fig, ax = plt.subplots()
# # 绘制每个圆
# for center in scaled_centers:
#     circle = plt.Circle(center, radius, fill=False, edgecolor='blue')
#     ax.add_artist(circle)
#
# 设置坐标轴范围
ax.set_xlim(-radius * 5, radius * 5)
ax.set_ylim(-radius * 5, radius * 5)
ax.set_aspect('equal', adjustable='box')

# 添加网格
ax.grid(True)
drawn_centers = set()
# 开始递归绘制蜂窝图
draw_honeycomb(ax, (0, 0), radius, 1, 2, drawn_centers)  # 这里设置最大深度为2，可以根据需要调整

# 显示图像
plt.show()
